﻿<UserControl x:Name="_root"
	x:Class="DemoSupport.DemoSet"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:demo="clr-namespace:DemoSupport"
	xmlns:con="http://schemas.kent.boogaart.com/converters">
	<UserControl.Resources>
		<con:MapConverter x:Key="VisibilityConverter">
			<con:Mapping From="{x:Null}" To="{x:Static Visibility.Collapsed}"/>
		</con:MapConverter>
	</UserControl.Resources>
	
	<TabControl DataContext="{Binding ElementName=_root}" ItemsSource="{Binding Demos}">
		<TabControl.ItemTemplate>
			<DataTemplate>
				<TextBlock Text="{Binding Title}"/>
			</DataTemplate>
		</TabControl.ItemTemplate>
		<TabControl.ContentTemplate>
			<DataTemplate>
				<ScrollViewer VerticalScrollBarVisibility="Auto">
					<StackPanel>
						<TextBlock Text="{Binding Description}" TextWrapping="Wrap"/>
						<ItemsControl ItemsSource="{Binding Steps}">
							<ItemsControl.ItemTemplate>
								<DataTemplate>
									<Grid Margin="0 0 0 15">
										<Grid.RowDefinitions>
											<RowDefinition Height="Auto"/>
											<RowDefinition Height="Auto"/>
											<RowDefinition Height="Auto"/>
											<RowDefinition Height="Auto"/>
										</Grid.RowDefinitions>
										<Grid.ColumnDefinitions>
											<ColumnDefinition Width="*"/>
											<ColumnDefinition Width="Auto"/>
										</Grid.ColumnDefinitions>

										<TextBlock Grid.Row="0" Text="{Binding Title}" Style="{DynamicResource Heading3}" VerticalAlignment="Bottom"/>
										<Button Grid.Column="1" Command="{Binding Command}" CommandParameter="{Binding CommandParameter}" Style="{DynamicResource Paragraph}">Execute</Button>

										<TextBlock Grid.Row="1" Grid.ColumnSpan="2" Text="{Binding Header}" Style="{DynamicResource Paragraph}" TextWrapping="Wrap" Visibility="{Binding Header, Converter={StaticResource VisibilityConverter}, FallbackValue={x:Static Visibility.Visible}}"/>
										
										<Border Grid.Row="2" Grid.ColumnSpan="2" BorderBrush="Black" BorderThickness="1" Padding="0" Margin="0 3 0 3" Visibility="{Binding Code, Converter={StaticResource VisibilityConverter}, FallbackValue={x:Static Visibility.Visible}}">
											<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" MaxHeight="100" Background="White">
												<FlowDocumentScrollViewer>
													<FlowDocument PagePadding="5">
														<Paragraph TextAlignment="Left">
															<demo:BindableRun BindableText="{Binding Code}" Style="{DynamicResource CodeBlock}"/>
														</Paragraph>
													</FlowDocument>
												</FlowDocumentScrollViewer>
											</ScrollViewer>
										</Border>

										<TextBlock Grid.Row="3" Grid.ColumnSpan="2" Text="{Binding Footer}" Style="{DynamicResource Paragraph}" TextWrapping="Wrap" Visibility="{Binding Footer, Converter={StaticResource VisibilityConverter}, FallbackValue={x:Static Visibility.Visible}}"/>
									</Grid>
								</DataTemplate>
							</ItemsControl.ItemTemplate>
						</ItemsControl>
					</StackPanel>
				</ScrollViewer>
			</DataTemplate>
		</TabControl.ContentTemplate>
	</TabControl>
</UserControl>
